<?php
namespace auth;

class ApiAuths{

    protected  $rangeTime = 300; // 服务器范围时间,单位为秒, 300 = 5分钟

    // 初始化 参数
    protected function __construct($options = []){
        
    }

	
    /**
     * 验证签名
     * @param String 
     * @return array
     */
    public function checkSign($param,$mckKey)
    {
        $sign = $param['sign']; unset( $param['sign'] );
        $str = self::getSign($param,$mckKey);
//      return true;
        return $sign === $str;  //签名
    }

	
	// ASCII 码从小到大排序
	public function getSign($params= array(),$key=''){
	    if(!empty($params)){
	       $p =  ksort($params);
	       if($p){
	           $str = '';
	            foreach ($params as $k=>$val){
	               if($val) $str .= $k .'=' . $val . '&';
	            }
	           $strs = rtrim($str, '&');
                return !$key ? $strs : strtoupper(md5( $strs.'&key='.($key ?: time())  ));
	       }
	    }
	    return '';
	}
	
   
}
